package be.gnx.logging4eclipse.perspective.model.logging;

import java.util.HashMap;

public enum EventLevel {

  ALL("ALL", 0),
  TRACE("TRACE", 1),
  DEBUG("DEBUG", 2),
  INFO("INFO", 3),
  WARN("WARN", 4),
  ERROR("ERROR", 5),
  FATAL("FATAL", 6),
  OFF("OFF", 7);

  private static final long serialVersionUID = 39580928759874l;

  private final String description;

  private final int intLevel;

  private static HashMap<String, EventLevel> eventLevelDescriptionHashMap = new HashMap<String, EventLevel>();

  private static HashMap<Integer, EventLevel> eventLevelIntegerHashMap = new HashMap<Integer, EventLevel>();

  static {
    for (EventLevel eventLevel : EventLevel.values()) {
      eventLevelDescriptionHashMap.put(eventLevel.description, eventLevel);
      eventLevelIntegerHashMap.put(eventLevel.intLevel, eventLevel);
    }
  }

  EventLevel(String description, int intLevel) {
    this.description = description;
    this.intLevel = (Integer.MAX_VALUE / 7) * intLevel;
  }

  public String getDescription() {
    return description;
  }

  public int getIntLevel() {
    return intLevel;
  }

  public static EventLevel typeOf(String description) {
    return eventLevelDescriptionHashMap.get(description);
  }

  public static EventLevel typeOf(int intLevel) {
    return eventLevelDescriptionHashMap.get(intLevel);
  }

}
